<?
class Navigator {
	var $links_visible=5;
	var $template='navigator';
	var $renderAdmin=true; // где брать темплейт
	var $hasPos=true;
	var $items;
	var $backLink;
	
	function Navigator(){
		$this->items = Array();
		}
	
	function Add($title,$url=""){
		$this->items[] = Array("title"=>$title,"url"=>$url);
		if($url) $this->backLink=$url;
		}
	
	function Render(){
		if(sizeof($this->items)==0) return "";
		// start templating
		if($this->renderAdmin)
			$temp = GetAdminTemplate($this->template);
		else
			$temp = GetSiteTemplate($this->template);
		
		$dao = Array();
		$dao["items"] = $this->items;
		return TemplaterParse($temp, $dao);
		}
	
	function GetBackLink(){
		return $this->backLink;
		}
	
	function reverse() {
		$this->items = array_reverse($this->items);
		if(sizeof($this->items)>0)
		{
			if($this->items[sizeof($this->items)-1]['url']) $this->backLink=$this->items[sizeof($this->items)-1]['url'];
			else if(sizeof($this->items)>1 && $this->items[sizeof($this->items)-2]['url']) $this->backLink=$this->items[sizeof($this->items)-2]['url'];
		}
		}
}
